package com.example.uidemo_01.Test;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.uidemo_01.R;
import com.example.uidemo_01.util.ToastUtil;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    //声明控件
    private Button mBtnLogin;
    private EditText mEtUser;
    private EditText mEtPassword;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        //找到控件
        mBtnLogin = findViewById(R.id.btn_login);
        mEtUser = findViewById(R.id.et_1);
        mEtPassword = findViewById(R.id.et_2);

//        //实现直接跳转----方法一
//        mBtnLogin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = null;
//                intent = new Intent(LoginActivity.this,SlideActivity.class);
//                startActivity(intent);
//            }
//        });

        //匹配对应的用户名和密码登录
        mBtnLogin.setOnClickListener(this);


    }

    public void onClick(View v){
        //需要获取输入的用户名和密码
        String username = mEtUser.getText().toString();
        String password = mEtPassword.getText().toString();
        //弹出内容设置
        String ok = "登录成功";
        String fail = "登录失败，账号或密码错误！";

        Intent intent = null;

        //假设正确的账号和密码分别是lxs，123456
        if(username.equals("lxs")&&password.equals("123456")){
            //Toast普通版
//            Toast.makeText(getApplicationContext(), ok, Toast.LENGTH_SHORT).show();

            //封装好的类
            ToastUtil.showMsg(LoginActivity.this,ok);

            //如果正确的话进行跳转
            intent = new Intent(LoginActivity.this, SlideActivity.class);
            startActivity(intent);
        }else{
            //不正确,弹出登录失败
            //提升版Toast，居中
//            Toast toastCenter = Toast.makeText(getApplicationContext(), fail, Toast.LENGTH_SHORT);
//            toastCenter.setGravity(Gravity.CENTER,0,0);
//            toastCenter.show();
            ToastUtil.showMsg(LoginActivity.this,fail);
        }

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}
